package sphere.controller;

import java.awt.Color;
import java.awt.TextField;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import sphere.model.Sphere;
import sphere.view.SphereWindow;

public class SphereController implements TextListener{

	SphereWindow src;
	
	public SphereController(SphereWindow src){
		this.src = src;
	}
	
	public void textValueChanged(TextEvent e) {
		TextField t = (TextField)e.getSource();
		if(t.getText().isEmpty()){
			t.setBackground(Color.pink);
			Sphere laSphere = new Sphere(0);
			src.setVolumeTextField(String.valueOf(laSphere.calculVolume()));
			src.setSurfaceTextField(String.valueOf(laSphere.calculSurface()));
		}
		else{	
			t.setBackground(Color.white);
			Sphere laSphere = new Sphere(Double.parseDouble(t.getText()));
			src.setVolumeTextField(String.valueOf(laSphere.calculVolume()));
			src.setSurfaceTextField(String.valueOf(laSphere.calculSurface()));
		}
	}
}
